home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / Int0.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  8.3 KB  |  275 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  Int0.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. /*         Int.h             */
  16.  
  17. /**************************************************************************
  18.     Headerfile for Int arithmetic in C++,
  19.  
  20.     RD, IWR Uni Heidelberg, 30.11.90
  21.  
  22. 16.12.91, RD    Redesigned the class Int to enable all operations between
  23.         Int and any of char, short, int, long or these unsigned.
  24.         To convert from Int to int, unsigned int ... the
  25.         functions Iisint, Iisuint, ... and intasI, uintasI, ...
  26.         are provided. All PLACE operators were removed.
  27.  
  28. june/juli 93    some changes for LEDA by S. Meiser & S. Naeher
  29.  
  30. *****************************************************************************/
  31.  
  32.  
  33. #ifndef _INT_H
  34. #define _INT_H
  35.  
  36. #include <LEDA/basic.h>
  37. #include <LEDA/impl/iint.h>
  38.  
  39. class Int {
  40.     Integer    I;
  41. public:
  42.     Int();
  43.     Int(int);
  44.     Int(unsigned int);
  45.     Int(long);
  46.     Int(unsigned long);
  47.     Int(const Int&);
  48.     ~Int();
  49.  
  50.     Int& operator=(const Int&);
  51.     int operator=(int);
  52.     
  53.     friend BOOLEAN Iisint(const Int&);
  54.     friend BOOLEAN Iisuint(const Int&);
  55.     friend BOOLEAN Iislong(const Int&);
  56.     friend BOOLEAN Iisulong(const Int&);
  57.     friend int intasI(const Int&);
  58.     friend unsigned int uintasI(const Int&);
  59.     friend long longasI(const Int&);
  60.     friend unsigned long ulongasI(const Int&);
  61.     friend double Itodouble(const Int&);
  62.  
  63.     friend int Ilog(const Int&);
  64.  
  65.     friend Int operator+(const Int&, const Int&);
  66.     friend Int operator-(const Int&, const Int&);
  67.     Int& operator+=(const Int&);
  68.     Int& operator-=(const Int&);
  69.     Int& operator++();
  70.     Int& operator--();
  71.  
  72.     /* Ergaenzung 07.05.92 SD */
  73.     friend Int operator-(const Int&);
  74.         
  75.         void negate();
  76.  
  77.     BOOLEAN operator!();
  78.     friend BOOLEAN operator==(const Int&, const Int&);
  79.     friend BOOLEAN operator>(const Int&, const Int&);
  80.     friend BOOLEAN operator!=(const Int&, const Int&);
  81.     friend BOOLEAN operator>=(const Int&, const Int&);
  82.     friend BOOLEAN operator<(const Int&, const Int&);
  83.     friend BOOLEAN operator<=(const Int&, const Int&);
  84.     friend Int operator*(const Int&, const Int&);
  85.     Int& operator*=(const Int&);
  86.     friend Int operator>>(const Int&, unsigned int);
  87.     friend Int operator<<(const Int&, unsigned int);
  88.     Int& operator>>=(unsigned int);
  89.     Int& operator<<=(unsigned int);
  90.     friend BOOLEAN Isr1(Int&);
  91.     friend BOOLEAN Ieven(const Int&);
  92.  
  93.     friend BOOLEAN Ige0(const Int&);
  94.     friend BOOLEAN Igt0(const Int&);
  95.     friend BOOLEAN Ile0(const Int&);
  96.     friend BOOLEAN Ilt0(const Int&);
  97.     friend BOOLEAN Ieq0(const Int&);
  98.     friend BOOLEAN Ieq1(const Int&);
  99.     friend int sign(const Int&); // returns +1, 0, -1
  100.     friend Int abs(const Int&);
  101.  
  102.     friend void Idiv(Int&, Int&, const Int&, const Int&);
  103.     friend void uIdiv(Int&, Int&, const Int&, const Int&);
  104.     friend Int operator/(const Int&, const Int&);
  105.     Int& operator/=(const Int&);
  106.     friend Int operator%(const Int&, const Int&);
  107.     Int& operator%=(const Int&);
  108.  
  109.     friend int fscanI(FILE*, Int&);
  110.     friend int fprintI(FILE*, const Int&);
  111.  
  112.     friend int Itoa(const Int&, char*);
  113.     friend int atoI(char*, Int&);
  114.  
  115.     friend Int gcd(const Int&, const Int&);        // "bester gcd" 
  116.     friend Int bgcd(const Int&, const Int&);    // binaerer gcd
  117.     friend Int dgcd(const Int&, const Int&);    // naiver gcd
  118.     friend Int elba(Int&, Int&, const Int&, const Int&);
  119.     friend Int belba(Int&, Int&, const Int&, const Int&);
  120.  
  121.     friend Int random(const Int&); // Zufallsgenerator
  122.  
  123. };
  124.  
  125. inline Int::Int()            { cI(&I); }
  126. inline Int::Int(int i)            { cIasint(&I, i); }
  127. inline Int::Int(unsigned int i)        { cIasuint(&I, i); }
  128. inline Int::Int(long i)            { cIaslong(&I, i); }
  129. inline Int::Int(unsigned long i)    { cIasulong(&I, i); }
  130. inline Int::Int(const Int &a)        { cIasI(&I, &a.I); }
  131. inline Int::~Int()            { dI(&I); }
  132.  
  133. inline Int& Int::operator=(const Int &a)
  134.   { IasI(&I, &a.I); return *this; }
  135. inline int Int::operator=(int i)
  136.   { Iasint(&I, i); return i; }
  137.     
  138. inline BOOLEAN Iisint(const Int &a)
  139.   { return Iisint(&a.I); }
  140. inline BOOLEAN Iisuint(const Int &a)
  141.   { return Iisuint(&a.I); }
  142. inline BOOLEAN Iislong(const Int &a)
  143.   { return Iislong(&a.I); }
  144. inline BOOLEAN Iisulong(const Int &a)
  145.   { return Iisulong(&a.I); }
  146. inline int intasI(const Int &a)
  147.   { return intasI(&a.I); }
  148. inline unsigned int uintasI(const Int &a)
  149.   { return uintasI(&a.I); }
  150. inline long longasI(const Int &a)
  151.   { return longasI(&a.I); }
  152. inline unsigned long ulongasI(const Int &a)
  153.   { return ulongasI(&a.I); }
  154. inline double Itodouble(const Int &a)
  155.   { return Itodouble(&a.I); }
  156.  
  157. inline Int& Int::operator+=(const Int& a)
  158.   { IplasI(&I, &a.I); return *this; }
  159. inline Int& Int::operator-=(const Int &a)
  160.   { ImiasI(&I, &a.I); return *this; }
  161. inline Int& Int::operator++()
  162.   { Iinc(&I); return *this; }
  163. inline Int& Int::operator--()
  164.   { Idec(&I); return *this; }
  165.  
  166. inline Int operator-(const Int &a)
  167.   { Int b(a); Ineg(&b.I); return b; }
  168.  
  169. inline void Int::negate()
  170.   { Ineg(&I); }
  171.  
  172. inline BOOLEAN Int::operator!()
  173.   { return Ieq0(&I); }
  174. inline BOOLEAN operator==(const Int &a, const Int &b) 
  175.   { return IeqI(&a.I, &b.I); }
  176. inline BOOLEAN operator>(const Int &a, const Int &b) 
  177.   { return IgtI(&a.I, &b.I); }
  178. inline BOOLEAN operator!=(const Int &a, const Int &b) 
  179.   { return IneI(&a.I, &b.I); }
  180. inline BOOLEAN operator>=(const Int &a, const Int &b) 
  181.   { return IgeI(&a.I, &b.I); }
  182. inline BOOLEAN operator<(const Int &a, const Int &b) 
  183.   { return IltI(&a.I, &b.I); }
  184. inline BOOLEAN operator<=(const Int &a, const Int &b) 
  185.   { return IleI(&a.I, &b.I); }
  186. inline Int& Int::operator*=(const Int &a)
  187.   { ImuasI(&I, &a.I); return *this; }
  188. inline Int& Int::operator>>=(unsigned int u)
  189.   { Israsint(&I, u); return *this; }
  190. inline Int& Int::operator<<=(unsigned int u)
  191.   { Islasint(&I, u); return *this; }
  192. inline BOOLEAN Isr1(Int &a)
  193.   { return Isr1(&a.I); }
  194. inline BOOLEAN Ieven(const Int &a) 
  195.   { return Ieven(&a.I); }
  196.  
  197. inline BOOLEAN Ige0(const Int &a)
  198.   { return Ige0(&a.I); }
  199. inline BOOLEAN Igt0(const Int &a)
  200.   { return Igt0(&a.I); }
  201. inline BOOLEAN Ile0(const Int &a)
  202.   { return Ile0(&a.I); }
  203. inline BOOLEAN Ilt0(const Int &a)
  204.   { return Ilt0(&a.I); }
  205. inline BOOLEAN Ieq0(const Int &a)
  206.   { return Ieq0(&a.I); }
  207. inline BOOLEAN Ieq1(const Int &a)
  208.   { return Ieq1(&a.I); }
  209. inline int sign(const Int &a)
  210.   { return sign(&a.I); } // returns +1, 0, -1
  211. inline Int abs(const Int &a)
  212.   { if (Ige0(&a.I)) { return a; } else { return -a; } }
  213.  
  214. inline void Idiv(Int &q, Int &r, const Int &a, const Int &b)
  215.   { Idiv(&q.I, &r.I, &a.I, &b.I); }
  216. inline void uIdiv(Int &q, Int &r, const Int &a, const Int &b)
  217.   { uIdiv(&q.I, &r.I, &a.I, &b.I); }
  218. inline Int& Int::operator/=(const Int &a)
  219.   { IdiasI(&I, &a.I); return *this; }
  220. inline Int& Int::operator%=(const Int &a)
  221.   { IreasI(&I, &a.I); return *this; }
  222.  
  223. inline int Ilog(const Int &a)    
  224.     { return Ilog(&a.I); }
  225.     
  226. inline Int operator+(const Int &a, const Int &b)
  227.     { Int c; IasIplI(&c.I, &a.I, &b.I); return c; }
  228. inline Int operator-(const Int &a, const Int &b)
  229.     { Int c; IasImiI(&c.I, &a.I, &b.I); return c; }
  230.  
  231. inline Int operator*(const Int &a, const Int &b)
  232.     { Int c; IasImuI(&c.I, &a.I, &b.I); return c; }
  233.  
  234. inline Int operator>>(const Int &a, unsigned int u)
  235.     { Int c; IasIsrint(&c.I, &a.I, u); return c; }
  236. inline Int operator<<(const Int &a, unsigned int u)
  237.     { Int c; IasIslint(&c.I, &a.I, u); return c; }
  238.  
  239. inline Int operator/(const Int &a, const Int &b)
  240.     { Int c; IasIdiI(&c.I, &a.I, &b.I); return c; }
  241. inline Int operator%(const Int &a, const Int &b)
  242.     { Int c; IasIreI(&c.I, &a.I, &b.I); return c; }
  243.  
  244. inline int fscanI(FILE * f, Int &a)
  245.     { return fscanI(f, &a.I); }
  246. inline int fprintI(FILE * f, const Int &a)
  247.     { return fprintI(f, &a.I); }
  248.  
  249. inline int Itoa(const Int &a, char s[])
  250.     { return Itoa(&a.I, s); }
  251. inline int atoI(char s[], Int &a)
  252.     { return atoI(s, &a.I); }
  253.  
  254. inline Int gcd(const Int &a, const Int &b)
  255.     { Int d; Igcd(&d.I, &a.I, &b.I); return d; }
  256. inline Int bgcd(const Int &a, const Int &b)
  257.     { Int d; Ibgcd(&d.I, &a.I, &b.I); return d; }
  258. inline Int dgcd(const Int &a, const Int &b)
  259.     { Int d; Idgcd(&d.I, &a.I, &b.I); return d; }
  260. inline Int elba(Int &u, Int &v, const Int &a, const Int &b)
  261.     { Int d; Ielba(&d.I, &u.I, &v.I, &a.I, &b.I); return d; }
  262. inline Int belba(Int &u, Int &v, const Int &a, const Int &b)
  263.     { Int d; Ibelba(&d.I, &u.I, &v.I, &a.I, &b.I); return d; }
  264.  
  265. inline Int random(const Int &b)
  266.     { Int a; IasrandomI(&a.I, &b.I); return a; }
  267.         
  268. ostream& operator<<(ostream &out, const Int &a);
  269. istream& operator>>(istream &in, Int &a);
  270.  
  271. const IN_INT_BUF_LENGTH=10000;
  272.  
  273. #endif
  274.